#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char	 op1[80];	/*定义全局变量op1可以返回多个值*/ 
int main(void)
{
	FILE	 *fp;
	FILE	 *fp1;
	FILE	 *fp2;
	char	 op2[80];
	char     ch1;
	char	 ch2; 
	int       n=0;
	int       i=0;
	
	void zhimupaixu(char op[], int n);	/*函数声明*/ 

/*打开文件*/	
	if((fp1 = fopen("b.txt", "r")) == NULL)
	{
		printf("File open error!\n");
		exit(0);
	}
	
	if((fp2 = fopen("a.txt", "r")) == NULL)
	{
		printf("File open error!\n");
		exit(0);
	}
	
	if((fp = fopen("c.txt", "w")) == NULL)
	{
		printf("File open error!\n");
		exit(0);
	}

/*读取字符到字符串变量中*/
 
	while(!feof(fp1))
	{
		
			ch1=fgetc(fp1);
			op1[n]=ch1;
			n++;				
	}
	
	while(!feof(fp2))
	{
	
			ch2=fgetc(fp2);
			op2[i]=ch2;
			i++;	
						
	}

/*将两个字符串连接为一个，并通过排序函数排序*/

		strcat(op1, op2);
		n=strlen(op1);
		zhimupaixu(op1, n);

/*将有序的字母字符录入到c.txt文件中*/ 
		
		for(i=0; i<n; i++)
		{
			if(op1[i]!=' ')
			{
				fprintf(fp, "%c", op1[i]);
			}
		}

/*关闭文件*/
		
	if(fclose(fp1))
	{
		printf("Can not close the file!\n");
		exit(0);
	}
	
	if(fclose(fp2))
	{
		printf("Can not close the file!\n");
		exit(0);
	}
	
	if(fclose(fp))
	{
		printf("Can not close the file!\n");
		exit(0);
	}
 } 

/*对字符数组进行选择排序*/
 
void zhimupaixu(char op[], int n)
{
	int    i;
	int    k;
	int    index;
	char   temp;
	
	for(k=0; k<n-1; k++)
	{	
		index = k;
		
		for(i=k+1; i<n; i++)
		{
			if(op[i] < op[index])
			{
				index = i;
			}
		}
		
		temp = op[index];
		op[index] = op[k];
		op[k] = temp;
	}
	
}